package com.topsec.manager.socket;

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author:huangyongqiang
 * @date:2018年12月27日 下午4:37:49
 * @since:JDK 1.8.0_171
 */

public class WebSocketMapUtil {
	// concurrent包的线程安全Set，用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话，可以使用Map来存放，其中Key可以为用户标识
	public static ConcurrentMap<String, MyWebSocket> webSocketMap = new ConcurrentHashMap<>();

	public static void put(String key, MyWebSocket myWebSocket) {
		webSocketMap.put(key, myWebSocket);
	}

	public static MyWebSocket get(String key) {
		return webSocketMap.get(key);
	}

	public static void remove(String key) {
		webSocketMap.remove(key);
	}

	public static Collection<MyWebSocket> getValues() {
		return webSocketMap.values();
	}
}
